package tempo.timing;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class AddRider extends Activity
{

	private EditText txtName;
	private EditText txtStartNumer;
	private Button btnAdd;
	private Button btnDelete;
	private EditText txtStartToRemove;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);

		setContentView(R.layout.add_rider);

		txtName = (EditText) findViewById(R.id.name);
		txtStartNumer = (EditText) findViewById(R.id.number);

		txtStartToRemove = (EditText) findViewById(R.id.txtStartToRemove);
		btnDelete = (Button) findViewById(R.id.btnDelete);
		btnDelete.setOnClickListener(new OnClickListener()
		{
			public void onClick(View v)
			{
				String sNum = txtStartToRemove.getText().toString();
				if (Race.getCurrent().delete(sNum))
					ToastHelper.DisplayToast(getBaseContext(), sNum + " deleted");
			}
		});

		btnAdd = (Button) findViewById(R.id.add);
		btnAdd.setOnClickListener(new View.OnClickListener()
		{

			public void onClick(View v)
			{
				String rname = txtName.getText().toString();
				if (Race.getCurrent().AddRider(rname, txtStartNumer.getText().toString()))
				{
					ToastHelper.DisplayToast(getBaseContext(), rname + " added");
				} else
				{
					ToastHelper.DisplayToast(getBaseContext(), "Rider need unique start number");
				}
			}
		});

	}

}
